//
// Created by Administrator on 2018-04-13.
//
#include <string.h>
#include "me_ywy_apt_mediaplayer_DNPlayer.h"
#include "stdlib.h"
#include "lib/libavutil/frame.h"
#include <android/native_window.h>

//Video *video = 0;
//char *path = 0;
ANativeWindow *window = 0;
//pthread_t p_tid;
//int isPlay = 0;


void *process(void*args){
//    pthread_exit(0);
}

//void call_video_play(AVFrame *frame){
//    if(!window){
//        return;
//    }
//    ANativeWindow_Buffer window_buffer;
//
//    if(ANativeWindow_lock(window , &window_buffer, 0)){
//        return;
//    }
//
//    uint8_t *dst = window_buffer.bits;
//
//    int datStride = window_buffer.stride * 4;
//
//    uint8_t  *src = frame->data[0];
//
//    int srcStride = frame->linesize[0];
//
//    for (int i = 0; i < window_buffer.height ; i++) {
//        memcpy(dst + i * datStride , src + i * srcStride , srcStride);
//    }
//    ANativeWindow_unlockAndPost(window);
//}

JNIEXPORT void JNICALL Java_me_ywy_apt_mediaplayer_DNPlayer_native_1play
        (JNIEnv *env, jobject, jstring url_){
//    const char *url = env->GetStringUTFChars(url_ ,0);
//
//    path = static_cast<char *>(malloc(strlen(url) + 1));
//    memset(path , 0 , strlen(url) + 1);
//    memcpy(path , url , strlen(url));
//
//    video = new Video;
//
//    video->setPlayCall(call_video_play);
//
//    pthread_creat(&p_tid , 0 , process , 0);
//    env->ReleaseStringUTFChars(url_ , url);

}


JNIEXPORT void JNICALL Java_me_ywy_apt_mediaplayer_DNPlayer_native_1set_1display
        (JNIEnv *env, jobject instance, jobject surface){
//    if(window){
//        ANativeWindow_release(window);
//        window=0;
//    }
//
//    window = ANativeWindow_fromSurface(env ,surface);
}


JNIEXPORT void JNICALL Java_me_ywy_apt_mediaplayer_DNPlayer_native_1stop
        (JNIEnv *env, jobject instance){

//    if(path){
//        free(path);
//        path = 0;
//    }
//
//    if(isPlay){
//        isPlay = 0;
//        pthread_join(p_tid , 0);
//    }
//
//    if(video){
//        if(video->isPlay){
//            video->stop();
//        }
//        delete(video);
//        video = 0;
//    }
}

JNIEXPORT void JNICALL Java_me_ywy_apt_mediaplayer_DNPlayer_native_1release
        (JNIEnv *env, jobject instance){
//    if(window){
//        ANativeWindow_release(window);
//    }
//    window = 0;

}
